package cn.hzking.gjmall.adpters.order;

import android.content.Intent;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.activitys.order.OrderDetailActivity;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.OrderBean;
import cn.hzking.gjmall.bean.order.OrderDetailBean;
import cn.hzking.gjmall.utils.FormatUtil;
import cn.hzking.gjmall.utils.IconTextSpanUtils;

/**
 * Created by Administrator on 2018/3/2.
 */

public class OrderDetailItemAdapter extends BaseQuickAdapter<OrderDetailBean.DataBean.OrderDOBean.OrderItemsBean,BaseViewHolder> {
    public OrderDetailItemAdapter(int layoutResId, @Nullable List<OrderDetailBean.DataBean.OrderDOBean.OrderItemsBean> data) {
        super(layoutResId, data);
    }
    private int orderId;
    private String status;
    private ApplyRefundInterface applyRefundInterface;

    public ApplyRefundInterface getApplyRefundInterface() {
        return applyRefundInterface;
    }

    public void setApplyRefundInterface(ApplyRefundInterface applyRefundInterface) {
        this.applyRefundInterface = applyRefundInterface;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public int getOrderId() {
        return orderId;
    }

    public void setOrderId(int orderId) {
        this.orderId = orderId;
    }


    @Override
    protected void convert(BaseViewHolder helper, final OrderDetailBean.DataBean.OrderDOBean.OrderItemsBean item) {
        ImageView iv=helper.getView(R.id.image_car_goods);
        TextView nameTv=helper.getView(R.id.tv_name);
        TextView priceTv=helper.getView(R.id.tv_price);
        TextView specTv=helper.getView(R.id.tv_spec);
        TextView oldpriceTv=helper.getView(R.id.tv_oldprice);
        TextView numTv=helper.getView(R.id.tv_num);
        TextView refundTv=helper.getView(R.id.tv_refund);
        RelativeLayout refundRl=helper.getView(R.id.rl_refund);

        if (getStatus().equals("ALREADY_SEND")){//如果状态为待收货并且商品种类大于1则显示申请售后按钮
            refundRl.setVisibility(View.VISIBLE);
            if(item.isNoRefund()){
                refundTv.setText("退款进程");
                refundTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        applyRefundInterface.schedule(item.getRefundId());
                    }
                });
            }else {
                refundTv.setText("申请退款");
                refundTv.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        applyRefundInterface.refund(item.getOrderId(),item.getItemId());
                    }
                });
            }
        }else {
            refundRl.setVisibility(View.GONE);
        }

        Glide.with(mContext).load(Gjmall.getOssHost()+item.getImageUrl()).into(iv);
        priceTv.setText("¥"+ FormatUtil.format(item.getPrice()));
        specTv.setText(item.getSkuname());
        IconTextSpanUtils.setText(mContext, item.getTitle(), item.getSellpattern(), nameTv,R.color.darkred);
        numTv.setText("x"+item.getNumber());
        oldpriceTv.setText("¥"+ FormatUtil.format(item.getOriginalPrice()));
        oldpriceTv.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG);
    }

    public interface ApplyRefundInterface {
        public void refund(int orderId,int orderItemId);
        public void schedule(int orderRefundId);
    }
}
